﻿using System.Collections;

namespace Sex
{
    public partial class Sex : System.Web.UI.Page
    {
        public class ListViewState : MyList
        {
            string GetError(System.Exception e)
            {
                if (e == null) return strNoData;
                string s = "";
                s += FormatMyKey("Data") + FormatMyText("=") + GetDictionary(e.Data) + "<br/>";
                s += FormatMyKey("HelpLink") + FormatMyText("=") + e.HelpLink + "<br/>";
                s += FormatMyKey("InnerException") + FormatMyText("=") + e.InnerException.ToString() + "<br/>";
                s += FormatMyKey("Message") + FormatMyText("=") + e.Message + "<br/>";
                s += FormatMyKey("Source") + FormatMyText("=") + e.Source + "<br/>";
                s += FormatMyKey("StackTrace") + FormatMyText("=") + e.StackTrace + "<br/>";
                s += FormatMyKey("TargetSite.Name") + FormatMyText("=") + e.TargetSite.Name;
                return s;
            }
            string GetErrors(System.Exception[] e)
            {
                string s = "";
                for (int i = 0; i < s.Length; i++)
                    s += FormatMyKey("Error " + i.ToString().PadLeft(2, '0')) + "<br/>" + GetError(e[i]);
                return s;
            }
            public ListViewState(State MyState, System.Web.UI.StateBag v)
                : base(MyState, "ViewState Objects")
            {
                if (v == null) Add("ListView", strNoData);
                if (v.Count == 0) Add("ListView", strNoData);
                IDictionaryEnumerator myDictionaryEnumerator = v.GetEnumerator();
                ICollection keys = v.Keys;
                foreach(string k in keys)
                {
                    switch (v[k].GetType().ToString())
                    {
                        default:
                        case "System.String":
                            Add(k, (v[k]).ToString());
                            break;
                        case "System.String[]":
                            string ss = "";
                            string[] s = ((string[])v[k]);
                            for (int i = 0; i < s.Length; i++)
                                ss += (ss == "" ? "" : ", ") + s[i];
                            Add(k, ss);
                            break;
                    }
                }
            }
        }
    }
}